#include "libz800.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <strings.h>

z800_device * z800;

#ifdef WIN32
#include <conio.h>
	int xgetch() 
	{
		return getch();
	}
#else
#include <iostream>
	int xgetch()
	{
		return std::cin.get();
	}
#endif

//---------------------------------------------------------------------------
int main(int argc, char ** argv)
{
	printf("z800 3D runner\nPass something to the command line to enable debugging\n");
	z800 = z800_connect(argc > 1 ? 10 : 0);
	if(!z800)
	{
		printf("cannot get z800!\n\tHave you installed the libusb driver for VID=0x1641 PID=0x120 AND VID=0x1641 PID=0x110? Use zadig\n");
		return -1;
	}
	//printf("z800 firmware 0x%X\n",z800_get_firmware_version(z800));
	z800_set_stereo_mode(z800,Z800_TRUE);
	printf("z800 stereo enabled\n");
	printf("Press q to exit, f to flip eyes,a to awake, m to mono, s to stereo\n");
	int c = -1;
	while((c = xgetch()) != -1)
	{
		if(c == 'q')
			break;
		else if(c == 'f')
		{
			z800_flip_stereo(z800);
			printf("eyes flipped\n");
		}
		else if(c == 'a')
		{
			z800_wake(z800);
			printf("awaken\n");
		}
		else if(c == 'm')
		{
			z800_set_stereo_mode(z800,Z800_FALSE);
			printf("mono mode\n");
		}
		else if(c == 's')
		{
			z800_set_stereo_mode(z800,Z800_TRUE);
			printf("stereo mode\n");			
		}
	}
	printf("disconnecting");
	z800_disconnect(z800);
	return 0;
}


